package my.codeandroid.antollroid;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class FareResultActivity extends Activity {
	private Bundle data;
	
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fare_result);
		
		data = (savedInstanceState == null)
					? getIntent().getExtras()
					: savedInstanceState;
		
		// Populate textviews
		TextView textView;
		textView = (TextView)findViewById(R.id.class1Text);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.CLASS_1)));
		
		textView = (TextView)findViewById(R.id.offPeakText);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.OFFPEAK_RATE)));
		
		textView = (TextView)findViewById(R.id.festiveRateText);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.FESTIVE_RATE)));
		
		textView = (TextView)findViewById(R.id.class2Text);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.CLASS_2)));
		
		textView = (TextView)findViewById(R.id.class3Text);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.CLASS_3)));
		
		textView = (TextView)findViewById(R.id.class4Text);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.CLASS_4)));
		
		textView = (TextView)findViewById(R.id.class5Text);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.CLASS_5)));
		
		textView = (TextView)findViewById(R.id.distanceText);
		textView.setText(String.format("%.2f", data.getFloat(DatabaseAdapter.DISTANCE)));
	}
	
	/*
	 * Save the fare information, so that it is recoverable when it comes back 
	 * to foreground.
	 * @see android.app.Activity#onSaveInstanceState(android.os.Bundle)
	 */
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		outState.putAll(data);
		super.onSaveInstanceState(outState);
	}
}